home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / pctj8410.arc / MYSUBS.ASM < prev    next >
Assembly Source File  |  1986-09-14  |  3KB  |  98 lines

  1. PAGE 58,132 
  2. TITLE MYSUBS -- example BASIC-callable subroutine image 
  3. NAME MYSUBS 
  4. COMMENT * 
  5.  
  6. This program may be freely copied and distributed.  The author 
  7. assumes no responsibility for its use or reliability. 
  8.  
  9. This program defines the dispatch table and entry points for 
  10. BASIC-callable subroutines.  The subroutine image is created 
  11. with the following commands: 
  12.  
  13.     MASM MYSUBS,MYSUBS,MYSUBS; 
  14.     LINK MYSUBS,,; 
  15.  
  16. Written 4/15/84 by Ron Bauman 
  17.  
  18. CSEG    SEGMENT BYTE PUBLIC 'CODE' 
  19.     ASSUME    CS:CSEG 
  20. DATA    SEGMENT    WORD PUBLIC 'DATA' 
  21. ;  define message strings 
  22. ERRMSG    DB '   Invalid subroutine call.',13,10,'$' 
  23. MSG1    DB '   Subroutine 1 executed.',13,10,'$' 
  24. MSG2    DB '   Subroutine 2 executed.',13,10,'$' 
  25. DATA    ENDS 
  26. ; Define the dispatch table.  The order of entries in this table must 
  27. ; correspond exactly with the order of name offset definitions in the 
  28. ; user's BASIC program.  Note that it must appear at location 0 in the  
  29. ; subroutine image.  This also means its segment must be defined first 
  30. ; to the linker. 
  31. MAIN    PROC    NEAR 
  32.     JMP    NEAR PTR CALLERR 
  33.                 ;error entry. catches improperly defined 
  34.                 ;offsets in user's program. 
  35.     JMP    NEAR PTR SUB1
  36.     JMP    NEAR PTR SUB2
  37. MAIN    ENDP 
  38. ; CALLable subroutines definition 
  39. SUB1    PROC    FAR        ;subroutine 1 
  40.     PUSH    DS        ;save BASIC's data space address 
  41.     MOV    AX,SEG DATA    ;get our data segment 
  42.     MOV    DS,AX 
  43.     ASSUME    DS:DATA 
  44.     MOV    DX,OFFSET MSG1    ;set up pointer to message 1 
  45.     MOV    AH,9H        ;print the string to standard output 
  46.     INT    21H 
  47.     POP    DS 
  48.     RET 
  49. SUB1    ENDP 
  50. SUB2    PROC    FAR        ;subroutine 2 
  51.     PUSH    DS        ;save BASIC's data space address 
  52.     MOV    AX,SEG DATA    ;get our data segment 
  53.     MOV    DS,AX 
  54.     ASSUME    DS:DATA 
  55.     MOV    DX,OFFSET MSG2    ;set up pointer to message 2 
  56.     MOV    AH,9H        ;print the string to standard output 
  57.     INT    21H 
  58.     POP    DS 
  59.     RET 
  60. SUB2    ENDP 
  61. ; The following routine catches calls to this image with an incorrectly 
  62. ; assigned offset.  The usual case is that the user has mistyped the 
  63. ; subroutine name, BASIC thought it was a new variable and assigned 
  64. ; zero to it. 
  65. CALLERR    PROC    FAR        ;subroutine 1 
  66.     PUSH    DS        ;save BASIC's data space address 
  67.     MOV    AX,SEG DATA    ;get our data segment 
  68.     MOV    DS,AX 
  69.     ASSUME    DS:DATA 
  70.     MOV    DX,OFFSET ERRMSG 
  71.                 ;set up pointer to our message 
  72.     MOV    AH,9H        ;print the string to standard output 
  73.     INT    21H 
  74.     POP    DS 
  75.     RET 
  76. CALLERR    ENDP 
  77. CSEG    ENDS 
  78.     END 
  79.